package com.aj.activity;

import android.content.Context;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.aj.activity.view.GestureContentView;
import com.aj.activity.view.GestureDrawl.GestureCallBack;
import com.aj.sharepreferences.LoveHomeSharedPreferences;
import com.aj.utils.PreferenceUtils;

public class HomesRelationGestureActivity extends BaseActivity {

    private FrameLayout body_layout;
    private GestureContentView content;
    private int index = 0;
    private String passwordString = "";
    private TextView alertmessage_text;
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_gesture);
        initView();
    }

    private void initView() {
        setActionBarTitle(R.string.safe_update_gesture_password_text);
        body_layout = (FrameLayout) findViewById(R.id.body_layout);
        alertmessage_text = (TextView) findViewById(R.id.alertmessage_text);
        content = new GestureContentView(this, "", new GestureCallBack() {
            @Override
            public void checkedSuccess() {
                verificationGesture();
            }

            @Override
            public void checkedFail() {
                verificationGesture();
            }
        });
        content.setParentView(body_layout);
    }

    private void verificationGesture() {
        if (index == 0) {
            index++;
            passwordString = content.getDrawl().getPassWordSb().toString();
            alertmessage_text.setText(getString(R.string.unlock_pic_two_text));
        } else if (index == 1) {
            if (passwordString.trim().equals(content.getDrawl().getPassWordSb().toString())) {
                Toast.makeText(mContext, getString(R.string.safe_update_gesture_password_success_text), Toast.LENGTH_LONG).show();
                LoveHomeSharedPreferences.insertHomesRelationGesturePassowrd(passwordString);
                PreferenceUtils.setHomesRelationIsFrist(mContext);
                finish();
            } else {
                Toast.makeText(mContext, getString(R.string.safe_update_gesture_password_error_text), Toast.LENGTH_LONG).show();
                index = 0;
                passwordString = "";
                alertmessage_text.setText(getString(R.string.unlock_pic_text));
            }
        }
    }
}
